import Vue from 'vue'
import Router from 'vue-router'
import homePage from '../views/homePage'
import classify from '../views/classify'

import my from '../views/my'
import myInfo from '../views/my/myInfo'

import shoppingCart from '../views/shoppingCart'
import Login from '../views/login'

import listdata from '../views/listdata'
import oneDetail from '../views/oneDetail'
import regsiter from '../views/regsiter'
import payment from '../views/shoppingCart/components/payment'

import noFont from '../views/noFont'


Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/homepage'
    }, {
      path: '/homepage',
      name: 'homepage',
      component: homePage
    }, {
      path: '/classify',
      name: 'classify',
      component: classify,
      
    }, {
      path: '/my',
      name: 'my',
      component: my
    }, {
      path: '/shoppingcart',
      name: 'shoppingcart',
      component: shoppingCart,
      meta: {
        required: true
      }

    },
    {
      path: '/login',
      name: 'login',
      component: Login,

    },{
      path: '/regsiter',
      name: 'regsiter',
      component: regsiter,

    },
   {
      path:'/listdata',
      name:'listdata',
      component:listdata
    },
 
    {
      path:'/onedetail/:id',
      name:'onedetail',
      component:oneDetail
    },
    {
      path:'/payment',
      name:'payment',
      component:payment
    },
    {
      path:'/myinfo',
      name:'myinfo',
      component:myInfo
    },
    {
      path:'/*',
      name:'nofont',
      component:noFont
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.required) {
    next({ name: 'login' });
    to.meta.required = false
  } else {
    next()
  }
})



export default router
